import React, { Component } from 'react';
import { View, StyleSheet, Text } from 'react-native';
import { ScrollView } from 'react-native-gesture-handler';
import { List, Flex, Toast, Badge, WingBlank } from '@ant-design/react-native';
import Item from '@ant-design/react-native/lib/list/ListItem';
import store from '~/store';
import { getOwnerParkingChatList, getOwnerBuildingChatList } from '~/api/message';

class MyConsultingService extends Component {
    static navigationOptions = {
        title: '咨询列表',
    };
    constructor(props) {
        super(props);
        const getter = store.getState();
        this.state = {
            id: '',
            owner_id: getter.userinfo.owner,
            itemname: '华帝王朝车位',
            itemnubber: 'B-21',
            itemfloor: '负一楼',
            itemaddress: '合川区华帝街32号',
            itembuiltup: '30',
            itemIntussusception: '25',
            itemprice: '80000',
            list: [],
            view_state: this.props.navigation.getParam('view_state'),
        };
        this.getList();
    }
    getList = () => {
        getOwnerBuildingChatList().then((r) => {
            if (r.code === 0) {
                this.setState({
                    list: r.data,
                });
            } else {
                Toast.info('失败', 1);
            }
        });
    };
    render() {
        return (
            <ScrollView style={styles.scrollview}>
                <WingBlank size={'lg'}>
                    <Flex>
                        <List style={styles.list}>
                            {this.state.list.map((item) => {
                                return (
                                    <Item
                                        style={styles.itemview}
                                        onPress={() => {
                                            this.props.navigation.push('Chat', {
                                                id: 0,
                                                getList: this.getList,
                                                route: 1,
                                                CompanyBuildingID: item.CompanyBuildingID,
                                                OwnerDataID: this.state.owner_id,
                                            });
                                        }}>
                                        <Flex>
                                            <Text style={styles.itemtext}>{item.BuildingName}</Text>
                                        </Flex>
                                        <Flex direction={'row'} justify={'between'}>
                                            <Text style={{ color: '#666666', fontSize: 12, marginTop: 5 }}>地址：{item.CityName}{item.Address}</Text>
                                            <Flex style={{ marginRight: 10, marginBottom: '6%' }}>
                                                {item.ViewState == 0 ? <Badge dot={true} /> : null}
                                            </Flex>
                                        </Flex>
                                    </Item>
                                );
                            })}
                        </List>
                    </Flex>
                </WingBlank>
            </ScrollView>
        );
    }
}
export default MyConsultingService;

const styles = StyleSheet.create({
    scrollview: {
        flex: 1,
    },
    list: {
        width: '100%',
        flexDirection: 'column',
        marginTop: 10,
    },
    itemtext: {
        fontSize: 15,
    },
    itemview: {
        width: '100%',
    },
});
